Conditions | 1 |
Paths | 1 |
Total Lines | 233 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
10 | jQuery(document).ready(function () { |
||
11 | /** |
||
12 | * Enable select2 |
||
13 | */ |
||
14 | jQuery( '.select2' ).select2(); |
||
15 | |||
16 | jQuery( '.select2Ajax' ).select2({ |
||
17 | ajax: { |
||
18 | url: ajaxurl, |
||
|
|||
19 | dataType: 'json', |
||
20 | delay: 250, |
||
21 | data: function (params) { |
||
22 | var term = jQuery(this).attr('data-term'); |
||
23 | return { |
||
24 | q: params.term, |
||
25 | term: term, |
||
26 | action: 'load_taxonomy_term' |
||
27 | }; |
||
28 | }, |
||
29 | processResults: function( data ) { |
||
30 | var options = []; |
||
31 | if ( data ) { |
||
32 | |||
33 | jQuery.each( data, function( index, text ) { |
||
34 | options.push( { id: text[0], text: text[1] } ); |
||
35 | }); |
||
36 | |||
37 | } |
||
38 | return { |
||
39 | results: options |
||
40 | }; |
||
41 | }, |
||
42 | cache: true |
||
43 | }, |
||
44 | minimumInputLength: 3 // the minimum of symbols to input before perform a search |
||
45 | }); |
||
46 | |||
47 | // Start Jetpack. |
||
48 | BulkWP.jetpack(); |
||
49 | |||
50 | BulkWP.enableHelpTooltips( jQuery( '.bd-help' ) ); |
||
51 | |||
52 | jQuery( '.user_restrict_to_no_posts_filter' ).change( function() { |
||
53 | var $this = jQuery(this), |
||
54 | filterEnabled = $this.is( ':checked' ), |
||
55 | $filterItems = $this.parents( 'table' ).children().find( '.user_restrict_to_no_posts_filter_items' ); |
||
56 | |||
57 | if ( filterEnabled ) { |
||
58 | $filterItems.removeClass( 'visually-hidden' ); |
||
59 | } else { |
||
60 | $filterItems.addClass( 'visually-hidden' ); |
||
61 | } |
||
62 | } ); |
||
63 | |||
64 | /** |
||
65 | * Enable Postbox handling |
||
66 | */ |
||
67 | postboxes.add_postbox_toggles(pagenow); |
||
68 | |||
69 | /** |
||
70 | * Toggle the date restrict fields |
||
71 | */ |
||
72 | function toggle_date_restrict(el) { |
||
73 | if (jQuery("#smbd" + el + "_restrict").is(":checked")) { |
||
74 | jQuery("#smbd" + el + "_op").removeAttr('disabled'); |
||
75 | jQuery("#smbd" + el + "_days").removeAttr('disabled'); |
||
76 | } else { |
||
77 | jQuery("#smbd" + el + "_op").attr('disabled', 'true'); |
||
78 | jQuery("#smbd" + el + "_days").attr('disabled', 'true'); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Toggle limit restrict fields |
||
84 | */ |
||
85 | function toggle_limit_restrict(el) { |
||
86 | if (jQuery("#smbd" + el + "_limit").is(":checked")) { |
||
87 | jQuery("#smbd" + el + "_limit_to").removeAttr('disabled'); |
||
88 | } else { |
||
89 | jQuery("#smbd" + el + "_limit_to").attr('disabled', 'true'); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Toggle user login restrict fields |
||
95 | */ |
||
96 | function toggle_login_restrict(el) { |
||
97 | if (jQuery("#smbd" + el + "_login_restrict").is(":checked")) { |
||
98 | jQuery("#smbd" + el + "_login_days").removeAttr('disabled'); |
||
99 | } else { |
||
100 | jQuery("#smbd" + el + "_login_days").attr('disabled', 'true'); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * Toggle user registered restrict fields |
||
106 | */ |
||
107 | function toggle_registered_restrict(el) { |
||
108 | if (jQuery("#smbd" + el + "_registered_restrict").is(":checked")) { |
||
109 | jQuery("#smbd" + el + "_registered_days").removeAttr('disabled'); |
||
110 | } else { |
||
111 | jQuery("#smbd" + el + "_registered_days").attr('disabled', 'true'); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Toggle Post type dropdown. |
||
117 | */ |
||
118 | function toggle_post_type_dropdown( el ) { |
||
119 | // TODO: Check why the element is not toggling even when display:none is added by JS. |
||
120 | if ( jQuery( "#smbd" + el + "_no_posts" ).is( ":checked" ) ) { |
||
121 | jQuery( "tr#smbd" + el + "-post-type-dropdown" ).show(); |
||
122 | } else { |
||
123 | jQuery( "tr#smbd" + el + "-post-type-dropdown" ).hide(); |
||
124 | } |
||
125 | } |
||
126 | |||
127 | // hide all terms |
||
128 | function hideAllTerms() { |
||
129 | jQuery('table.terms').hide(); |
||
130 | jQuery('input.terms').attr('checked', false); |
||
131 | } |
||
132 | // call it for the first time |
||
133 | hideAllTerms(); |
||
134 | |||
135 | // taxonomy click handling |
||
136 | jQuery('.custom-tax').change(function () { |
||
137 | var $this = jQuery(this), |
||
138 | $tax = $this.val(), |
||
139 | $terms = jQuery('table.terms_' + $tax); |
||
140 | |||
141 | if ($this.is(':checked')) { |
||
142 | hideAllTerms(); |
||
143 | $terms.show('slow'); |
||
144 | } |
||
145 | }); |
||
146 | |||
147 | // date time picker |
||
148 | jQuery.each(BulkWP.dt_iterators, function (index, value) { |
||
149 | // invoke the date time picker |
||
150 | jQuery('#smbd' + value + '_cron_start').datetimepicker({ |
||
151 | timeFormat: 'HH:mm:ss' |
||
152 | }); |
||
153 | |||
154 | jQuery('#smbd' + value + '_restrict').change(function () { |
||
155 | toggle_date_restrict(value); |
||
156 | }); |
||
157 | |||
158 | jQuery('#smbd' + value + '_limit').change(function () { |
||
159 | toggle_limit_restrict(value); |
||
160 | }); |
||
161 | |||
162 | jQuery('#smbd' + value + '_login_restrict').change(function () { |
||
163 | toggle_login_restrict(value); |
||
164 | }); |
||
165 | |||
166 | jQuery('#smbd' + value + '_registered_restrict').change(function () { |
||
167 | toggle_registered_restrict(value); |
||
168 | }); |
||
169 | |||
170 | jQuery( '#smbd' + value + '_no_posts' ).change( function () { |
||
171 | toggle_post_type_dropdown( value ); |
||
172 | }); |
||
173 | }); |
||
174 | |||
175 | jQuery.each( BulkWP.pro_iterators, function ( index, value) { |
||
176 | jQuery('.bd-' + value.replace( '_', '-' ) + '-pro').hide(); |
||
177 | jQuery('#smbd_' + value + '_cron_freq, #smbd_' + value + '_cron_start, #smbd_' + value + '_cron').removeAttr('disabled'); |
||
178 | } ); |
||
179 | |||
180 | // Validate user action |
||
181 | jQuery('button[name="bd_action"]').click(function () { |
||
182 | var currentButton = jQuery(this).val(), |
||
183 | valid = false, |
||
184 | msg_key = "deletePostsWarning", |
||
185 | error_key = "selectPostOption"; |
||
186 | |||
187 | if (currentButton in BulkWP.validators) { |
||
188 | valid = BulkWP[BulkWP.validators[currentButton]](this); |
||
189 | } else { |
||
190 | if (jQuery(this).parent().prev().children('table').find(":checkbox:checked[value!='true']").size() > 0) { // monstrous selector |
||
191 | valid = true; |
||
192 | } |
||
193 | } |
||
194 | |||
195 | if (valid) { |
||
196 | if (currentButton in BulkWP.pre_action_msg) { |
||
197 | msg_key = BulkWP.pre_action_msg[currentButton]; |
||
198 | } |
||
199 | |||
200 | return confirm(BulkWP.msg[msg_key]); |
||
201 | } else { |
||
202 | if (currentButton in BulkWP.error_msg) { |
||
203 | error_key = BulkWP.error_msg[currentButton]; |
||
204 | } |
||
205 | |||
206 | alert(BulkWP.msg[error_key]); |
||
207 | } |
||
208 | |||
209 | return false; |
||
210 | }); |
||
211 | |||
212 | /** |
||
213 | * Validation functions |
||
214 | */ |
||
215 | BulkWP.noValidation = function() { |
||
216 | return true; |
||
217 | }; |
||
218 | |||
219 | BulkWP.validateSelect2 = function(that) { |
||
220 | if (null !== jQuery(that).parent().prev().children().find(".select2[multiple]").val()) { |
||
221 | return true; |
||
222 | } else { |
||
223 | return false; |
||
224 | } |
||
225 | }; |
||
226 | |||
227 | BulkWP.validateUrl = function(that) { |
||
228 | if (jQuery(that).parent().prev().children('table').find("textarea").val() !== '') { |
||
229 | return true; |
||
230 | } else { |
||
231 | return false; |
||
232 | } |
||
233 | }; |
||
234 | |||
235 | BulkWP.validateUserMeta = function() { |
||
236 | if (jQuery('#smbd_u_meta_value').val() !== '') { |
||
237 | return true; |
||
238 | } else { |
||
239 | return false; |
||
240 | } |
||
241 | }; |
||
242 | }); |
||
243 | |||
292 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.